#ifndef PACKET_H
#define PACKET_H

#include <QObject>
#include <QDataStream>
#include <QBitArray>
#include <QHostAddress>

#include <QBuffer>
#include "packetdata.h"

class Packet
{
public:
    Packet(QByteArray byteArr);
    Packet();

    void setProtocolId(const quint32& id);
    void setSequence(const quint32& s);
    void setAck(const quint32& a);
    void setAckBitfield(const QBitArray& bf);

    void setIsReliable(const bool& is);
    void setSendTime(const quint32& st);
    void setData(PacketData* d);

    void setSenderAddress(const QHostAddress& addr);
    void setSenderPort(const quint16& p);

    quint32 getProtocolId();
    quint32 getSequence();
    quint32 getAck();
    QBitArray getAckBitfield();
    QByteArray getData();
    QString getStringData();
    bool getIsReliable();
    quint32 getSendTime();

    QHostAddress getSenderAddress();
    quint16 getSenderPort();

    QByteArray toByteArray();
    void fromByteArray(QByteArray arr);

    QString getHostPortKey();

private:
    qint32 protocol_id;
    quint32 sequence;
    quint32 ack;
    quint32 sendTime;
    QBitArray ack_bitfield;

    QHostAddress senderAddress;
    quint16 senderPort;

    bool isReliable;

    QByteArray data;
};

#endif // PACKET_H
